package cn.lkx.eduservice.controller;


import cn.lkx.commonutils.R;
import cn.lkx.eduservice.entity.EduChapter;
import cn.lkx.eduservice.entity.EduVideo;
import cn.lkx.eduservice.service.EduVideoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author lkx
 * @since 2022-05-03
 */
@Api(description="课程小节课时管理")
@RestController
@RequestMapping("/eduservice/video")
@CrossOrigin
public class EduVideoController {
    @Autowired
    EduVideoService videoService;

    //添加小节
    @PostMapping("addVideo")
    public R addVideo(@RequestBody EduVideo eduVideo){
        videoService.save(eduVideo);
        return R.ok();
    }
    //通过小节id获取小节信息 ，做回显
    @GetMapping("getVideoById/{videoId}")
    public R getVideoById(@PathVariable String videoId){
        EduVideo eduVideo = videoService.getById(videoId);
        return R.ok().data("video",eduVideo);
    }
    //修改小节
    @PostMapping("updateVideo")
    public R updateVideo(@RequestBody EduVideo eduVideo){
        videoService.updateById(eduVideo);
        return R.ok();
    }
    //删除小节
    //TODO 后面需要完善阿里云上小节视频的删除 （已完善）
    @DeleteMapping("deleteVideo/{videoId}")
    public R deleteVideo(@PathVariable String videoId){
        videoService.deleteVideoById(videoId);  //必须先删除视频在删除小节
        boolean result = videoService.removeById(videoId);
        if (result){
            return R.ok();
        }else {
            return R.error();
        }
    }
}

